// middleware.ts (根目录)
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { handlePathname } from './middleware/pathname'
import { handleAuth } from './middleware/auth'
import { handleRedirect } from './middleware/redirect'
// import { handleLogging } from './middleware/logging'

export async function middleware(request: NextRequest) {
  let response = NextResponse.next()

  // 执行路径处理 middleware
  // 按顺序执行中间件
  // response = await handleLogging(request, response) // 先记录日志
  response = await handleRedirect(request, response) // 再处理路径
  response = await handlePathname(request, response) // 再处理路径
  response = await handleAuth(request, response)

  return response
}

export const config = {
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
}
